package ru.papergames.web.blines.battle.network.clientpackets;

import ru.papergames.common.form.PcPlayerForm;
import ru.papergames.common.netutils.ModelWriterUtils;

import java.io.UnsupportedEncodingException;

/**
 * @author Alexander Troshanin
 */
public class AddNewPcPlayer extends WebServerClientPacket {

    private PcPlayerForm player;
    private int secretKey;

    public AddNewPcPlayer(PcPlayerForm player, int secretKey) {
        this.player = player;
        this.secretKey = secretKey;
    }

    @Override
    protected void writePacketId() {
        writeC(ADD_NEW_PC_PLAYER_PACKET_ID);
    }

    @Override
    protected void writePacketData() {
        writeD(secretKey);
        ModelWriterUtils.writePlayerToBuffer(_buf, player);
    }

    @Override
    public String getType() {
        return "[c] AddNewPcPlayer[" + ADD_NEW_PC_PLAYER_PACKET_ID + "]";
    }
}
